package com.zhiyun.test.base.listener;

import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;

/**
 * Created by user on 2019-5-27.
 */
public class RetryFail implements IRetryAnalyzer {
  private int retryCount = 0;
  private int maxRetryCount = 3;
  @Override
  public boolean retry(ITestResult iTestResult) {
    if (retryCount < maxRetryCount) {
      System.out.println("Retrying test " + iTestResult.getName() + " with status "
        + getResultStatusName(iTestResult.getStatus()) + " for the " + (retryCount+1) + " time(s).");
      retryCount++;
      return true;
    }
    return false;
  }
  public String getResultStatusName(int status) {//这个函数将状态码转换为状态文字。
    String resultName = null;
    if(status==1)
      resultName = "SUCCESS";
    if(status==2)
      resultName = "FAILURE";
    if(status==3)
      resultName = "SKIP";
    return resultName;
  }
}
